package com.example.demodb.controller;

import com.example.demodb.entity.Song;
import com.example.demodb.entity.SongSong;
import com.example.demodb.entity.UserSong;
import com.example.demodb.service.SongService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
public class SongController {
    @Resource
    private SongService songService;
    @GetMapping("/SongController/findAll")
    public List<Song> findAll(){
        return songService.findAll();
    }

    @GetMapping("/SongController/deleteById/{id}")
    public void delete(@PathVariable String id){
        songService.delete(id);
    }

    @GetMapping("/SongController/findById/{id}")
    public Song findById(@PathVariable String id){
        return songService.findSongById(id);
    }

    @PostMapping("/SongController/findSimSongsByTitle")
    public List<List<SongSong>> findSimSongsByTitle(@RequestParam String title){
        return songService.findSimSongsByTitle(title);
    }

    //借口原名为SongController/saveUser, 将检查用户是否存在,新增用户的功能放到一起
    //如果这里不分开写的话,也合理,因为check的返回值就可以定义成int了,这样子就不会出现空对象前端无法识别的问题
    @PostMapping("/SongController/add") //RO表示该接口 会返回一个对象
    public Song add(@RequestBody Song song){
        return songService.add(song);//返回为空的话,就说明为0
    }

    @PostMapping("/SongController/update") //RO表示该接口 会返回一个对象
    public Song update(@RequestBody Song song){
        return songService.update(song);//返回为空的话,就说明为0
    }

    @GetMapping("/SongController/addSong1Song2/{songId1}/{songId2}/{sim}") //RO表示该接口 会返回一个对象
    public SongSong addSongSong(@PathVariable String songId1, @PathVariable String songId2, @PathVariable(required = false) Double sim){
        return songService.addSongSong(songId1, songId2, sim);//返回为空的话,就说明为0
    }

    @PostMapping("/SongController/addSong1Song2ByTitle") //RO表示该接口 会返回一个对象
    public SongSong addSongSongByTitle(@RequestParam String songTitle1, @RequestParam String songTitle2, @RequestParam(required = false) Double sim){
        return songService.addSongSongByTitle(songTitle1, songTitle2, sim);//返回为空的话,就说明为0
    }

    @GetMapping("/SongController/findSong1Song2Sim/{songId1}/{songId2}") //RO表示该接口 会返回一个对象
    public SongSong findSong1Song2Sim(@PathVariable String songId1, @PathVariable String songId2){
        return songService.findSong1Song2Sim(songId1, songId2);//返回为空的话,就说明为0
    }
    @GetMapping("/SongController/randomGenerateSongsByNum/{num}") //RO表示该接口 会返回一个对象
    public List<Song> randomGenerateSongsByNum(@PathVariable Integer num){
        return songService.randomGenerateSongsByNum(num);
    }

    //注意这里是限制了返回的歌曲数量
    @GetMapping("/SongController/findSongsByStyle")
    public List<Song> findSongsByStyle(@RequestParam("style") String style){
        return songService.findSongsByStyle(style);
    }

    @GetMapping("/SongController/findSongsByTitle")
    public Song findSongsByTitle(@RequestParam("title") String title){
        return songService.findSongsByTitle(title);
    }

    @GetMapping("/SongController/findAllBySearchContains")
    public List<Song> findAllBySearchContains(@RequestParam("search") String search){
        return songService.findAllBySearchContains(search);
    }

}
